<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<%

'获取提交查询的参数
my=trim(SafeRequest("my",0))
tx_search=trim(SafeRequest("tx_search",0))
dept=trim(SafeRequest("dept",0))
empe=trim(SafeRequest("empe",0))
post=trim(SafeRequest("post",0))
touch=trim(SafeRequest("touch",0))
success=trim(SafeRequest("success",0))
location=trim(SafeRequest("location",0))
source=trim(SafeRequest("source",0))
target=trim(SafeRequest("target",0))
forget=trim(SafeRequest("forget",0))
assist=trim(SafeRequest("assist",0))
visit=trim(SafeRequest("visit",0))
orderby=trim(SafeRequest("orderby",0))
memo=trim(SafeRequest("memo",0))
visit_ksrq=trim(SafeRequest("visit_ksrq",0))
if visit_ksrq<>"" then visit_ksrq=cdate(visit_ksrq)
visit_jsrq=trim(SafeRequest("visit_jsrq",0))
if visit_jsrq<>"" then visit_jsrq=cdate(visit_jsrq)
search_count=trim(SafeRequest("search_count",0))

'组合sql查询字符串
sql="select crm.*,crm_empe.empe as empename,crm_location.location as locationname,crm_post.post as postname from crm left join crm_post on crm.post=crm_post.id left join crm_empe on crm.empe=crm_empe.id left join crm_location on crm_location.id=crm.location where 1 "
if tx_search<>"" then
	sql=sql&" and (company like '%"&tx_search&"%' or address like '%"&tx_search&"%' or web like '%"&tx_search&"%' or crm.memo like '%"&tx_search&"%')"
end if
if session("iDept")<>0 then dept=session("iDept")
if dept<>"" then
	sql_dept="select id from crm_empe where dept="&dept
	' response.write sql_dept
	set rs_dept = Server.CreateObject("ADODB.Recordset")
	' rs_dept.cursorlocation=3
	rs_dept.open sql_dept,conn,1,1
	if not rs_dept.eof then
		str_empe=rs_dept.getstring(,,,",")
		if right(str_empe,1)="," then str_empe=left(str_empe,len(str_empe)-1)
	end if
	' response.write str_empe
	' response.end
	rs_dept.close
	set rs_dept=nothing
	sql=sql&" and crm.empe in ("&str_empe&") "
end if
if session("bCaptain")<>1 then empe=session("iId")


if empe<>"" then sql=sql&" and crm.empe="&empe
if post<>"" then sql=sql&" and crm.post="&post
if location<>"" then sql=sql&" and crm.location="&location
if touch<>"" then sql=sql&" and touch="&touch
if success<>"" then sql=sql&" and success="&success
if source<>"" then sql=sql&" and source like '%"&source&"%'"
if target<>"" then sql=sql&" and target like '%"&target&"%'"
if forget<>"" then sql=sql&" and forget="&forget
if assist<>"" then sql=sql&" and assist="&assist
if visit<>"" then sql=sql&" and visit="&visit
if visit_ksrq<>"" and visit_jsrq<>"" then	sql=sql&" and (cd_date>=#"&visit_ksrq&"# and cd_date<=#"&visit_jsrq&"#)"

sql=sql&" order by "&orderby&" desc "
if search_count<>"" then sql=sql&" limit "&search_count

if my="my" then sql="select crm.*,crm_empe.empe as empename,crm_location.location as locationname,crm_post.post as postname from crm left join crm_post on crm.post=crm_post.id left join crm_empe on crm.empe=crm_empe.id left join crm_location on crm_location.id=crm.location where forget=0 and crm.empe="&session("iId")&" and crm.post in (2,3) order by crm_update desc"

' response.write sql
' response.end
'执行数据查询
set rs = Server.CreateObject("ADODB.Recordset")
rs.cursorlocation=3
rs.open sql,conn,1,1
If rs.eof Then
	response.write("没有检索到数据!")
	response.end
End if

'分页控制
If saferequest("page",0)<>"" Then	page=clng(saferequest("page",0)) Else	page=1
pc=saferequest("pc",1)
If pc="" Then pc=25
rs.pagesize=pc
pagesize=rs.pagesize
pagecount=rs.pagecount
'page=clng(request.QueryString("page"))
if Not IsEmpty(page) then '如果page_num已经初始化...
	if Not IsNumeric(page) then '判断page_num值是否为数字
		page=1
	else
		page = clng(page) '接收page_num并化为数字型赋给page_num变量
	end if
	if page > pagecount then '如果接收的页数大于总页数
		rs.AbsolutePage = pagecount '设置当前显示页等于最后页
	elseif page <= 0 then '如果page小于等于0
		page=1
		rs.AbsolutePage = page '设置当前显示页等于第一页
	else
		rs.AbsolutePage = page '如果大于零,显示当前页等于接收的页数
	end if
	page = rs.AbsolutePage
end if
%>
<table class="full">
	<thead>
		<tr>
			<%if not my="my" then%>
			<th scope="col"><input type="checkbox" id="checkall"></th>
			<%end if%>
			<th scope="col">序号</th>
			<th scope="col">客户名称</th>
			<th scope="col">客户地址</th>
			<th scope="col">客户地区</th>
			<th scope="col">箱量</th>
			<th scope="col">单量</th>
			<th scope="col">主要工厂</th>
			<th scope="col">主要方向</th>
			<th scope="col">交易方式</th>
			<%if not my="my" then%>
			<th scope="col">处理人</th>
			<%end if%>
			<th scope="col">岗位</th>
			<th scope="col">联系过</th>
			<th scope="col">结果</th>
			<th scope="col">历时</th>
			<th scope="col">备注</th>
		</tr>
	</thead>
	<tbody>
<%
For i=1 To pagesize
	If rs.eof Then Exit for
%>
		<tr class="post_<%=rs("post")%> <%if rs("post")=4 then response.write(" success_"&rs("success"))%>">
			<%if not my="my" then%>
			<th class="sub" scope="row"><input type="checkbox" name="checkid" class="checkid" value="<%=rs("id")%>|<%=rs("forget")%>|<%=rs("post")%>|<%=rs("empe")%>|<%=rs("success")%>|<%=rs("touch")%>|<%=rs("dispatcher")%>" /></th>
			<%end if%>
			<th class="sub" scope="row"><%=rs.AbsolutePosition%></th>
			<td><a href="crm.asp?id=<%=rs("id")%>" target="_blank"><%=rs("company")%></a></td>
			<td><%=rs("address")%></td>
			<td><%=rs("locationname")%></td>
			<td class="tac"><%=rs("boxs")%></td>
			<td class="tac"><a show="false" class="tbl_cd" href="companyid=<%=rs("id")%>"><%=rs("cds")%></a></td>
			<td title="<%=rs("source")%>"><%=ShortString(rs("source"),20)%></td>
			<td title="<%=rs("target")%>"><%=ShortString(rs("target"),20)%></td>
			<td title="<%=rs("change")%>"><%=ShortString(rs("change"),20)%></td>
			<%if not my="my" then%>
			<td class="tac"><%=rs("empename")%></td>
			<%end if%>
			<td class="tac"><%=rs("postname")%></td>
			<td class="tac"><%if rs("touch")=1 then response.write("√")%></td>
			<td class="tac"><%if rs("success")=1 then response.write("√")%></td>
			<td class="tac"><%if rs("post")=2 or rs("post")=3 then response.write(DateDiff("d",rs("post_update"),Date()))%></td>
			<td><%=rs("memo")%></td>
		</tr>

<%
	rs.movenext()
next
%>
	</tbody>
</table>
<div>
	<span id="actionbar">
		<%if session("iDept")=0 and session("bCaptain")=1 and my="" then%>
		<input class="bt_button" id="bt_forget" type="button" value="忽略" />
		<%end if%>
		<%if session("bCaptain")=1 and my="" then%>
		<input class="bt_button" id="bt_dispatch" type="button" value="派单" />
		<%end if%>
	</span>
	<span id="pagebar">
		共查询到&nbsp;<%=rs.RecordCount%>&nbsp;条记录&nbsp;
		<%	If page>1 Then	%>
			[<a href="#" id="1">首页</a>]
			[<a href="#" id="<%=page-1%>">上一页</a>]
		<%
				End If
				If Not (page>=pagecount Or pagecount=0) Then
		%>
			[<a href="#" id="<%=page+1%>">下一页</a>]
			[<a href="#" id="<%=pagecount%>">尾页</a>]
		<%	End If %>
			第 <%=page%> 页 / 共 <%=pagecount%> 页
			转到<input id="page_val" type="text" size="2" maxlength="<%=Int(Log(pagecount))+1%>" value="<%=page%>" />页
			<input id="page_go" class="bt_button" type="button" value="Go" />
	</span>
</div>
<%
rs.close
Set rs=nothing


function ShortString(sSourceString,iLimitNumber)
	dim sShortStr
	sShortStr=left(sSourceString,iLimitNumber)
	if right(sShortStr,1)=")" then
		ShortString=sShortStr
	else
		ShortString=left(sShortStr,InStrRev(sShortStr,",")-1)
	end if
end function

%>

<!--#include file="lib/connclose.asp"-->

